package ru.urfc.portal.ui.client.renderers;

import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.renderers.colorers.BaseColorer;
import ru.urfc.portal.ui.client.renderers.colorers.FakeColorer;
import ru.urfc.portal.ui.client.widgets.MegaGrid;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public abstract class SimpleRenderer extends BaseRenderer {
	protected Element element;
	protected BaseColorer colorer = FakeColorer.INSTANCE;

	public SimpleRenderer(GridField field, Element element) {
		super(field);
		this.element = element;
	}

	@Override
	protected void init(MegaGrid grid) {
		element = grid.getCatalogItemTemplate();
		colorer.init(grid);
	}
	
	@Override
	public Object renderCell(ModelData modelData) {
		String text = render(modelData);
		return colorer.colorCell(text, modelData);
	}

	@Override
	public void renderElements(ModelData modelData) {
		element.setInnerText(render(modelData));
		colorer.colorElements(modelData);
	}
	
	public abstract String render(ModelData modelData);

	@Override
	public void updateModel(ModelData modelData) {		
	}
}
